package com.hzit.pool.executor.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@Configuration
public class MyThreadPoolExecutor {
	@Bean
	public ThreadPoolExecutor poolExecutor(ThreadPoolExecutorProperties properties){
		return new ThreadPoolExecutor(
				properties.getCorePoolSize(),
				properties.getMaxSize(),
				properties.getKeepAliveTime(),
				TimeUnit.SECONDS,
				new LinkedBlockingDeque<>(properties.getBlockingDequeSize()),          //默认为整数最大值，内存为溢出
				Executors.defaultThreadFactory(),
				new ThreadPoolExecutor.AbortPolicy()
		);
	}
}
